<template>
    <div id="subtmpl">
        <div class="inleft div" @click="substrict">-</div>
        <div class="incenter div" v-text="count"></div>
        <div class="inright div" @click="add">+</div>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                count:1
            }
        },
        methods:{
            add(){
                this.count++;
                // if(this.count > )
                this.sendmessage();
            },
            substrict(){
                this.count--;
                if(this.count <1){
                    this.count = 1;
                    
                }
                this.sendmessage();
            },
            sendmessage(){
                this.$emit('dataobj',this.count);       //#emit是 从子组件 向 父组件提交数据   props属性是 父组件向子组件传递
            }
        }
    }
</script>

<style scoped>
    #subtmpl .div{
        width: 40px;
        height: 25px;
        border: 1px solid #000;
        line-height: 20px;
        text-align: center;
        display: inline-block;
    }
</style>

